#include <bits/stdc++.h>
using namespace std;
int f[10010], a[10010], g[10010];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	f[1] = a[1] == 1 ? 0 : 1;
	g[n] = a[n] == 1 ? 0 : 1;
	for(int i = 2; i <= n; i++)
		f[i] = f[i-1] + (a[i] - 1);
	for(int i = n-1; i >= 1; i--)
		g[i] = g[i+1] + (a[i] % 2);
	int Min = 0x7fffffff;
	for(int i = 0; i <= n; i++)
		Min = min(f[i] + g[i+1], Min);
	cout << Min;
	return 0;
}